#ifndef _AMERICO_OS_FILE_H_
#define _AMERICO_OS_FILE_H_

#include <iostream>
#include <fstream>
#include <bitset>
#include <string>

namespace OperatingSystem
{
	enum FileFlags
	{
		READ   = 0x1,
		WRITE  = 0x2,
		APPEND = 0x4,
		BINARY = 0x8
	};

	enum FileTestFlags
	{
		T_READ   = 0,
		T_WRITE  = 1,
		T_APPEND = 2,
		T_BINARY = 3
	};

	typedef std::bitset<8> FileFlagsType;

	class File
	{
	private:
		FileFlagsType myFlags;
		std::fstream myFile;
		std::string myFileName;

	public:
		File();
		File(const std::string aFileName, FileFlagsType aSetOfFlags=0xF);
		~File();

		bool Open(const std::string aFileName, FileFlagsType aSetOfFlags=0xF);
		bool Close();

		bool GoToNewLine();
		inline bool ReadToNewLine() { return GoToNewLine(); }

		bool ReadInt(int &aInteger);
		bool ReadInt(unsigned int &aInteger);
		bool ReadFloat(float &aFloat);
		bool ReadDouble(double &aDouble);
		bool ReadWord(std::string &aString);
		bool ReadString(std::string &aString);
		bool ReadBool(bool& aFlag);

		bool WriteString(std::string aString);
		bool WriteInt(int &aInteger);
		bool WriteFloat(float &aFloat);
		bool WriteDouble(double &aDouble);
		bool WriteBool(bool& aFlag);

		bool WriteData(void *someData, int aSizeToWrite);
		bool ReadData(void *someData, int aSizeToRead);

		bool FlushToDisk();

		unsigned int GetFileSize();

		bool Clear();
		bool IsOpen() const;
		bool Eof() const;

		const std::string& GetFileName();
	};
};

namespace OS = OperatingSystem;

#endif
